<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./vue.js"></script>
</head>
<body>
    <div id="app">
        <child content="Dell"></child>
        <child content="Lee"></child>
    </div>
    <script>
    //bus/发布订阅模式/观察者模式
        Vue.prototype.bus=new Vue()
        Vue.component('child',{
            data:function(){
                return{
                    selfContent:this.content
                }
            },
            props:{
                content:String
            },
            template:'<div @click="handle">{{selfContent}}</div>',
            methods:{
                handle:function(){
                    this.bus.$emit('change',this.selfContent)//向外触发事件
                }
            },
            mounted:function(){
                var this1=this;
                this.bus.$on('change',function(msg){//监测事件change
                    this1.selfContent=msg
                })
            }

        })
        var vm=new Vue({
            el:'#app',
        })
    </script>
</body>
</html>